<?php 
/****
author:N++
email:
license:
****/

namespace Admin\Model;
use Think\Model;

// class CateModel extends Model{
// 	public function getTree(){
// 		return $this->select();
// 	}
// }
class CateModel extends Model{
	protected $cats = array();

	public function __construct(){
		parent::__construct();
		$this->cates = $this->select();
	}
	//获取栏目树
	public function getTree( $parent_id=0 , $level=0 ){
		$tree = array();
		foreach($this->cates as $c){// 循环取cates数组里的值
			if($c['parent_id'] == $parent_id){
				$c['level'] = $level;
				$tree[] = $c;

				//然后,继续查这个cat_id的parent_id下面的
				$tree = array_merge($tree , $this->getTree( $c['cat_id'] , $level+1 ));
			}
		}
		return $tree;
	}
}

?>